package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.TbTeacher;
import com.ruoyi.product.service.ITbTeacherService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 所属教师Controller
 * 
 * @author Sun
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/teacher")
public class TbTeacherController extends BaseController
{
    @Autowired
    private ITbTeacherService tbTeacherService;

    /**
     * 查询所属教师列表
     */
    @RequiresPermissions("product:teacher:list")
    @GetMapping("/list4")
    public TableDataInfo list(TbTeacher tbTeacher)
    {
        startPage();
        List<TbTeacher> list = tbTeacherService.selectTbTeacherList(tbTeacher);
        return getDataTable(list);
    }

    /**
     * 导出所属教师列表
     */
    @RequiresPermissions("product:teacher:export")
    @Log(title = "所属教师", businessType = BusinessType.EXPORT)
    @PostMapping("/export4")
    public void export(HttpServletResponse response, TbTeacher tbTeacher)
    {
        List<TbTeacher> list = tbTeacherService.selectTbTeacherList(tbTeacher);
        ExcelUtil<TbTeacher> util = new ExcelUtil<TbTeacher>(TbTeacher.class);
        util.exportExcel(response, list, "所属教师数据");
    }

    /**
     * 获取所属教师详细信息
     */
    @RequiresPermissions("product:teacher:query")
    @GetMapping(value = "/getInfo4/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Integer teacherId)
    {
        return success(tbTeacherService.selectTbTeacherByTeacherId(teacherId));
    }

    /**
     * 新增所属教师
     */
    @RequiresPermissions("product:teacher:add")
    @Log(title = "所属教师", businessType = BusinessType.INSERT)
    @PostMapping("/add4")
    public AjaxResult add(@RequestBody TbTeacher tbTeacher)
    {
        return toAjax(tbTeacherService.insertTbTeacher(tbTeacher));
    }

    /**
     * 修改所属教师
     */
    @RequiresPermissions("product:teacher:edit")
    @Log(title = "所属教师", businessType = BusinessType.UPDATE)
    @PutMapping("/edit4")
    public AjaxResult edit(@RequestBody TbTeacher tbTeacher)
    {
        return toAjax(tbTeacherService.updateTbTeacher(tbTeacher));
    }

    /**
     * 删除所属教师
     */
    @RequiresPermissions("product:teacher:remove")
    @Log(title = "所属教师", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove4/{teacherIds}")
    public AjaxResult remove(@PathVariable Integer[] teacherIds)
    {
        return toAjax(tbTeacherService.deleteTbTeacherByTeacherIds(teacherIds));
    }
}
